package com.movie.utils;
import java.text.DecimalFormat;

public class RateUtil {
    public static Double[] getAvgRateAndPoint(double rate){
        Double[] res = new Double[3];
        int x = (int) (rate/1);
        double y = rate%1;
        if(y>=0.0&&y<0.25){
            y = 0.0;
        }
        if(y>=0.25&&y<0.75){
            y = 0.5;
        }
        if(y>=0.75){
            y = 1.0;
        }
        //用于给星星评分渲染的分数，只能以0.5或.0结尾
        res[0] = x+y;


        //平均分保留一位小数点后一位
        res[1] = Double.valueOf(String.format("%.1f",rate));

        //以平均分为基础，转换为10分制的分数
        DecimalFormat df = new DecimalFormat("#.0");
        res[2]= Double.valueOf(df.format((res[1]/5)*10));
        return res;
    }

    public static void main(String[] args) {
        double x = 4.0154;
        System.out.println(getAvgRateAndPoint(x)[0]);
        System.out.println(getAvgRateAndPoint(x)[1]);
        System.out.println(getAvgRateAndPoint(x)[2]);
    }
}
